/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏李涛
 * Date: 2024-06-04
 * Time: 17:02
 */
import jdk.jshell.execution.Util;

/**
 * 翻转数组
 */

public class Test2 {
   public static void reverse(int[] nums, int begin, int end) {
       while (begin < end) {
           int tmp = nums[begin];
           nums[begin] = nums[end];
           nums[end] = tmp;
           begin++;
           end--;
       }
   }

    public static void rotate(int[] nums, int k) {
       k %= nums.length;
        reverse(nums, 0, nums.length-1);//整体交换
        reverse(nums, k, nums.length-1);//交换后k个
        reverse(nums, 0, k-1);//交换前k个
    }

}
